package controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import po.Result;
import po.SimpleStrategy;
import service.SimpleStrategyService;

import java.util.List;

@Controller
@RequestMapping("/simpleStrategy")
public class SimpleStrategyController {
    @Autowired
    private SimpleStrategyService simpleStrategyService;

    @RequestMapping("/getSimpleStrategyView")
    public String getSimpleStrategyView() {
        return "strategy/simpleStrategy";
    }

    @RequestMapping("/findAllSimpleStrategies")
    public @ResponseBody
    List<SimpleStrategy> findAllSimpleStrategies() throws Exception {
        return simpleStrategyService.findAllSimpleStrategies();
    }

    @RequestMapping("/getAddSimpleStrategyView")
    public String getAddSimpleStrategyView() {
        return "strategy/addSimpleStrategy";
    }

    @RequestMapping("/addSimpleStrategy")
    public @ResponseBody
    Result addSimpleStrategy(SimpleStrategy simpleStrategy) {
        return simpleStrategyService.addSimpleStrategy(simpleStrategy);
    }

    @RequestMapping("/deleteSimpleStrategyById")
    public @ResponseBody
    Result deleteSimpleStrategyById(int id) {
        return simpleStrategyService.deleteSimpleStrategyById(id);
    }

    @RequestMapping("/getEditSimpleStrategyView")
    public String getEditSimpleStrategyView() {
        return "strategy/editSimpleStrategy";
    }

    @RequestMapping("/updateSimpleStrategy")
    public @ResponseBody
    Result updateSimpleStrategy(SimpleStrategy simpleStrategy) {
        return simpleStrategyService.updateSimpleStrategyById(simpleStrategy.getId(), simpleStrategy);
    }
}
